#ifndef SM_COMMON_H
#define SM_COMMON_H

typedef unsigned char u8;
typedef unsigned int u32;
typedef unsigned long long u64;
typedef long long i64;


// 32位大小端转换
#define Rev(m) ((u32)(m)[0] << 24 | (u32)(m)[1] << 16 | (u32)(m)[2] <<  8 | (u32)(m)[3])
#define Put(ptr, a) ((ptr)[0] = ((a) >> 24), (ptr)[1] = ((a) >> 16), (ptr)[2] = ((a) >>  8), (ptr)[3] = (a))

//  清除
#define Clean(m) memset(m, 0, sizeof(m))

typedef u64 fp[8];
typedef u64 dfp[16];
typedef u8 byt[32];
typedef char str[64];
typedef u8 bit[256];
typedef int naf[257];

typedef struct {
    fp x;
    fp y;
} point;

typedef struct {
    fp x;
    fp y;
    fp z;
} jpoint;

typedef struct {
    fp p;
    fp a;
    fp b;
    fp n;
    point g;
} curve;

typedef u8 sm2_bn[32];

typedef struct {
    sm2_bn x;
    sm2_bn y;
} sm2_point;

typedef sm2_point sm2_public_key;

typedef struct {
    sm2_public_key pubkey;
    sm2_bn prikey;
} sm2_private_key;

typedef struct {
    sm2_bn p;
    sm2_bn a;
    sm2_bn b;
    sm2_bn n;
    sm2_bn gx;
    sm2_bn gy;
} curve_inf;

typedef struct {
    sm2_bn r;
    sm2_bn s;
} sm2_signature;

typedef struct {
    sm2_bn x;
    sm2_bn y;
    u8 hash[32];
    u8 *ctext;
    u32 clen;
} sm2_ciptext;

#endif //SM_COMMON_H
